import React, { Component } from 'react';
import { Form, Input, Select } from "antd"

const { Option } = Select;

class AddCategory extends Component {

    UNSAFE_componentWillMount(){
        this.props.getForm(this.props.form);
    }

    render() {
        const { getFieldDecorator } = this.props.form;
        const {categoryList} =this.props;
        return (
            <div>
                <Form>
                    <Form.Item>
                        {
                            getFieldDecorator("categoryGrade", {
                                initialValue:"0"
                            })(
                                <Select>
                                    <Option value="0">一级分类</Option>
                                    {
                                        categoryList.map(item=>{
                                            return <Option value={item._id} key={item._id}>{item.categoryName}</Option>
                                        })
                                    }
                                </Select>
                            )
                        }
                    </Form.Item>
                    <Form.Item>
                        {
                            getFieldDecorator("categoryName",{
                                rules:[
                                    { required: true, message: '分类名不能为空！' }
                                ]
                            })(
                                <Input placeholder="请输入分类名称"></Input>
                            )
                        }
                    </Form.Item>
                </Form>
            </div>
        );
    }
}
const WrappedNormalLoginForm = Form.create()(AddCategory)
export default WrappedNormalLoginForm;